package cn.main.controller;

import cn.main.core.SessionHelper;
import cn.main.core.UserSession;
import cn.main.service.SysService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;


/**
 * Author: chengwei
 * Date:   2016/5/10
 * Time:   17:30
 */
@Controller
@RequestMapping("/user/sys")
public class SysController {
    
    @Resource
    private SysService service;
    
    @RequestMapping("/home")
    public ModelAndView req(HttpServletRequest req, HttpServletResponse resp) throws Exception {
//        service.get
        UserSession session = SessionHelper.getUserSession(req);
        if (session == null) {
            return new ModelAndView("/home");
        }
        Map<String,Object> map = service.getCarousel(session.getUser(),req.getParameter("function_id"));
        return new ModelAndView("/home",map);
    }

    @RequestMapping("/ma")
    public ModelAndView getManager(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        //获取栏目
        UserSession session = SessionHelper.getUserSession(req);
        if (session == null) {
            return new ModelAndView("/home");
        }
        return new ModelAndView("/manager/manager");
    }

    @RequestMapping(value = "/ful")
    @ResponseBody
    public Map<String,Object> getFunction(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        //获取构架 
        UserSession session = SessionHelper.getUserSession(req);
        String columnId = req.getParameter("column_id");
        Map<String,Object> map = service.getFunction(session.getUser(),columnId);
        return map;
    }

    @RequestMapping("/f")
    public ModelAndView getPageForWord(String p) throws Exception {
        return new ModelAndView(p);
    }
    
}
